package cn.tdzk;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import optimal.response.ResponseOptHour;
import optimal.service.impl.OptimalHour;
import org.json.JSONObject;
import southernGrid.CBLRS;
import southernGrid.ISS;
import southernGrid.OpenTower;
import southernGrid.User;

public class AlgorithmOptimalHour {
    public JSONObject doOptimalHour(JSONObject data) {
        int N_DOCU = data.getInt("N_DOCU");
        String DOCU_Form = data.getString("DOCU_Form");
        double nominalCoolingLoad_DOCU = data.getDouble("nominalCoolingLoad_DOCU");
        double nominalCoolingElectricPower_DOCU = data.getDouble("nominalCoolingElectricPower_DOCU");
        double nominalCoolingTin_load_DOCU = data.getDouble("nominalCoolingTin_load_DOCU");
        double nominalCoolingTout_load_DOCU = data.getDouble("nominalCoolingTout_load_DOCU");
        double nominalCoolingTin_source_DOCU = data.getDouble("nominalCoolingTin_source_DOCU");
        double nominalCoolingTout_source_DOCU = data.getDouble("nominalCoolingTout_source_DOCU");
        double[] cooling_Parameter_DOCU1 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_DOCU1"));
        double[] cooling_Parameter_DOCU2 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_DOCU2"));
        double[] cooling_Parameter_DOCU3 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_DOCU3"));
        double[] cooling_Parameter_DOCU4 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_DOCU4"));
        double coolingTout_Set_min_DOCU = data.getDouble("coolingTout_Set_min_DOCU");
        double coolingTout_Set_max_DOCU = data.getDouble("coolingTout_Set_max_DOCU");
        double nominalIceMakingLoad_DOCU = data.getDouble("nominalIceMakingLoad_DOCU");
        double nominalIceMakingElectricPower_DOCU = data.getDouble("nominalIceMakingElectricPower_DOCU");
        double nominalIceMakingTin_load_DOCU = data.getDouble("nominalIceMakingTin_load_DOCU");
        double nominalIceMakingTout_load_DOCU = data.getDouble("nominalIceMakingTout_load_DOCU");
        double nominalIceMakingTin_source_DOCU = data.getDouble("nominalIceMakingTin_source_DOCU");
        double nominalIceMakingTout_source_DOCU = data.getDouble("nominalIceMakingTout_source_DOCU");
        double[] IceMaking_Parameter_DOCU1 = DataConverter.toDoubleArray(data.getString("IceMaking_Parameter_DOCU1"));
        double[] IceMaking_Parameter_DOCU2 = DataConverter.toDoubleArray(data.getString("IceMaking_Parameter_DOCU2"));
        double[] IceMaking_Parameter_DOCU3 = DataConverter.toDoubleArray(data.getString("IceMaking_Parameter_DOCU3"));
        double[] IceMaking_Parameter_DOCU4 = DataConverter.toDoubleArray(data.getString("IceMaking_Parameter_DOCU4"));
        double IceMakingTout_Set_min_DOCU = data.getDouble("IceMakingTout_Set_min_DOCU");
        double IceMakingTout_Set_max_DOCU = data.getDouble("IceMakingTout_Set_max_DOCU");
        int N_IceStorageTank_ISS = data.getInt("N_IceStorageTank_ISS");
        double iceStorageCapacity_IceStorageTank_ISS = data.getDouble("iceStorageCapacity_IceStorageTank_ISS");
        double[] geometricDimensioning_IceStorageTank_ISS = DataConverter.toDoubleArray(data.getString("geometricDimensioning_IceStorageTank_ISS"));
        String pipeType_IceStorageTank_ISS = data.getString("pipeType_IceStorageTank_ISS");
        int N_tubePasses_IceStorageTank_ISS = data.getInt("N_tubePasses_IceStorageTank_ISS");
        int N_channels_everyPass_IceStorageTank_ISS = data.getInt("N_channels_everyPass_IceStorageTank_ISS");
        double Din_tube_IceStorageTank_ISS = data.getDouble("Din_tube_IceStorageTank_ISS");
        double Dout_tube_IceStorageTank_ISS = data.getDouble("Dout_tube_IceStorageTank_ISS");
        double Dout_corrugatedTube_IceStorageTank_ISS = data.getDouble("Dout_corrugatedTube_IceStorageTank_ISS");
        double nominalChargeTin_IceStorageTank_ISS = data.getDouble("nominalChargeTin_IceStorageTank_ISS");
        double nominalChargeTout_IceStorageTank_ISS = data.getDouble("nominalChargeTout_IceStorageTank_ISS");
        double nominalChargeFlow_IceStorageTank_ISS = data.getDouble("nominalChargeFlow_IceStorageTank_ISS");
        double nominalDisChargeTin_IceStorageTank_ISS = data.getDouble("nominalDisChargeTin_IceStorageTank_ISS");
        double nominalDisChargeTout_IceStorageTank_ISS = data.getDouble("nominalDisChargeTout_IceStorageTank_ISS");
        double nominalDisChargeFlow_IceStorageTank_ISS = data.getDouble("nominalDisChargeFlow_IceStorageTank_ISS");
        double[] charge_Parameter_IceStorageTank_ISS = DataConverter.toDoubleArray(data.getString("charge_Parameter_IceStorageTank_ISS"));
        double[] discharge_Parameter_IceStorageTank_ISS = DataConverter.toDoubleArray(data.getString("discharge_Parameter_IceStorageTank_ISS"));
        double baseChargeLoad = data.getDouble("baseChargeLoad");
        double baseDisChargeLoad = data.getDouble("baseDisChargeLoad");
        int N_plateHeatExchanger_ISS = data.getInt("N_plateHeatExchanger_ISS");
        double exchangeArea_plateHeatExchanger_ISS = data.getDouble("exchangeArea_plateHeatExchanger_ISS");
        double nominalPrimarySideTin_plateHeatExchanger_ISS = data.getDouble("nominalPrimarySideTin_plateHeatExchanger_ISS");
        double nominalPrimarySideTout_plateHeatExchanger_ISS = data.getDouble("nominalPrimarySideTout_plateHeatExchanger_ISS");
        double nominalPrimarySideFlow_plateHeatExchanger_ISS = data.getDouble("nominalPrimarySideFlow_plateHeatExchanger_ISS");
        double nominalSecondarySideTin_plateHeatExchanger_ISS = data.getDouble("nominalSecondarySideTin_plateHeatExchanger_ISS");
        double nominalSecondarySideTout_plateHeatExchanger_ISS = data.getDouble("nominalSecondarySideTout_plateHeatExchanger_ISS");
        double nominalSecondarySideFlow_plateHeatExchanger_ISS = data.getDouble("nominalSecondarySideFlow_plateHeatExchanger_ISS");
        double[] heatTransfer_Parameter_plateHeatExchanger_ISS = DataConverter.toDoubleArray(data.getString("heatTransfer_Parameter_plateHeatExchanger_ISS"));
        int N_User1Pump_ISS = data.getInt("N_User1Pump_ISS");
        double nominalFlow_User1Pump_ISS = data.getDouble("nominalFlow_User1Pump_ISS");
        double nominalHead_User1Pump_ISS = data.getDouble("nominalHead_User1Pump_ISS");
        double minFrequency_User1Pump_ISS = data.getDouble("minFrequency_User1Pump_ISS");
        double maxFrequency_User1Pump_ISS = data.getDouble("maxFrequency_User1Pump_ISS");
        double[] flowHead_User1Pump_Parameter_ISS = DataConverter.toDoubleArray(data.getString("flowHead_User1Pump_Parameter_ISS"));
        double[] flowEfficiency_User1Pump_Parameter_ISS = DataConverter.toDoubleArray(data.getString("flowEfficiency_User1Pump_Parameter_ISS"));
        double[] flow_User1Pump_ISS = DataConverter.toDoubleArray(data.getString("flow_User1Pump_ISS"));
        int N_SourcePump_ISS = data.getInt("N_SourcePump_ISS");
        double nominalFlow_SourcePump_ISS = data.getDouble("nominalFlow_SourcePump_ISS");
        double nominalHead_SourcePump_ISS = data.getDouble("nominalHead_SourcePump_ISS");
        double minFrequency_SourcePump_ISS = data.getDouble("minFrequency_SourcePump_ISS");
        double maxFrequency_SourcePump_ISS = data.getDouble("maxFrequency_SourcePump_ISS");
        double[] flowHead_SourcePump_Parameter_ISS = DataConverter.toDoubleArray(data.getString("flowHead_SourcePump_Parameter_ISS"));
        double[] flowEfficiency_SourcePump_Parameter_ISS = DataConverter.toDoubleArray(data.getString("flowEfficiency_SourcePump_Parameter_ISS"));
        double[] flow_SourcePump_ISS = DataConverter.toDoubleArray(data.getString("flow_SourcePump_ISS"));
        int N_EthylAlcoholPump_ISS = data.getInt("N_EthylAlcoholPump_ISS");
        double nominalFlow_EthylAlcoholPump_ISS = data.getDouble("nominalFlow_EthylAlcoholPump_ISS");
        double nominalHead_EthylAlcoholPump_ISS = data.getDouble("nominalHead_EthylAlcoholPump_ISS");
        double minFrequency_EthylAlcoholPump_ISS = data.getDouble("minFrequency_EthylAlcoholPump_ISS");
        double maxFrequency_EthylAlcoholPump_ISS = data.getDouble("maxFrequency_EthylAlcoholPump_ISS");
        double[] flowHead_EthylAlcoholPump_Parameter_ISS = DataConverter.toDoubleArray(data.getString("flowHead_EthylAlcoholPump_Parameter_ISS"));
        double[] flowEfficiency_EthylAlcoholPump_Parameter_ISS = DataConverter.toDoubleArray(data.getString("flowEfficiency_EthylAlcoholPump_Parameter_ISS"));
        double[] flow_EthylAlcoholPump_ISS = DataConverter.toDoubleArray(data.getString("flow_EthylAlcoholPump_ISS"));
        ISS iss = new ISS(N_DOCU, DOCU_Form, nominalCoolingLoad_DOCU, nominalCoolingElectricPower_DOCU, nominalCoolingTin_load_DOCU, nominalCoolingTout_load_DOCU, nominalCoolingTin_source_DOCU, nominalCoolingTout_source_DOCU, cooling_Parameter_DOCU1, cooling_Parameter_DOCU2, cooling_Parameter_DOCU3, cooling_Parameter_DOCU4, coolingTout_Set_min_DOCU, coolingTout_Set_max_DOCU, nominalIceMakingLoad_DOCU, nominalIceMakingElectricPower_DOCU, nominalIceMakingTin_load_DOCU, nominalIceMakingTout_load_DOCU, nominalIceMakingTin_source_DOCU, nominalIceMakingTout_source_DOCU, IceMaking_Parameter_DOCU1, IceMaking_Parameter_DOCU2, IceMaking_Parameter_DOCU3, IceMaking_Parameter_DOCU4, IceMakingTout_Set_min_DOCU, IceMakingTout_Set_max_DOCU, N_IceStorageTank_ISS, iceStorageCapacity_IceStorageTank_ISS, geometricDimensioning_IceStorageTank_ISS, pipeType_IceStorageTank_ISS, N_tubePasses_IceStorageTank_ISS, N_channels_everyPass_IceStorageTank_ISS, Din_tube_IceStorageTank_ISS, Dout_tube_IceStorageTank_ISS, Dout_corrugatedTube_IceStorageTank_ISS, nominalChargeTin_IceStorageTank_ISS, nominalChargeTout_IceStorageTank_ISS, nominalChargeFlow_IceStorageTank_ISS, nominalDisChargeTin_IceStorageTank_ISS, nominalDisChargeTout_IceStorageTank_ISS, nominalDisChargeFlow_IceStorageTank_ISS, charge_Parameter_IceStorageTank_ISS, discharge_Parameter_IceStorageTank_ISS, baseChargeLoad, baseDisChargeLoad, N_plateHeatExchanger_ISS, exchangeArea_plateHeatExchanger_ISS, nominalPrimarySideTin_plateHeatExchanger_ISS, nominalPrimarySideTout_plateHeatExchanger_ISS, nominalPrimarySideFlow_plateHeatExchanger_ISS, nominalSecondarySideTin_plateHeatExchanger_ISS, nominalSecondarySideTout_plateHeatExchanger_ISS, nominalSecondarySideFlow_plateHeatExchanger_ISS, heatTransfer_Parameter_plateHeatExchanger_ISS, N_User1Pump_ISS, nominalFlow_User1Pump_ISS, nominalHead_User1Pump_ISS, minFrequency_User1Pump_ISS, maxFrequency_User1Pump_ISS, flowHead_User1Pump_Parameter_ISS, flowEfficiency_User1Pump_Parameter_ISS, flow_User1Pump_ISS, N_SourcePump_ISS, nominalFlow_SourcePump_ISS, nominalHead_SourcePump_ISS, minFrequency_SourcePump_ISS, maxFrequency_SourcePump_ISS, flowHead_SourcePump_Parameter_ISS, flowEfficiency_SourcePump_Parameter_ISS, flow_SourcePump_ISS, N_EthylAlcoholPump_ISS, nominalFlow_EthylAlcoholPump_ISS, nominalHead_EthylAlcoholPump_ISS, minFrequency_EthylAlcoholPump_ISS, maxFrequency_EthylAlcoholPump_ISS, flowHead_EthylAlcoholPump_Parameter_ISS, flowEfficiency_EthylAlcoholPump_Parameter_ISS, flow_EthylAlcoholPump_ISS);
        int N_BLRU = data.getInt("N_BLRU");
        String BLRU_Form = data.getString("BLRU_Form");
        double nominalCoolingLoad_BLRU = data.getDouble("nominalCoolingLoad_BLRU");
        double nominalCoolingElectricPower_BLRU = data.getDouble("nominalCoolingElectricPower_BLRU");
        double nominalCoolingTin_load_BLRU = data.getDouble("nominalCoolingTin_load_BLRU");
        double nominalCoolingTout_load_BLRU = data.getDouble("nominalCoolingTout_load_BLRU");
        double nominalCoolingTin_source_BLRU = data.getDouble("nominalCoolingTin_source_BLRU");
        double nominalCoolingTout_source_BLRU = data.getDouble("nominalCoolingTout_source_BLRU");
        double[] cooling_Parameter_BLRU1 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_BLRU1"));
        double[] cooling_Parameter_BLRU2 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_BLRU2"));
        double[] cooling_Parameter_BLRU3 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_BLRU3"));
        double[] cooling_Parameter_BLRU4 = DataConverter.toDoubleArray(data.getString("cooling_Parameter_BLRU4"));
        double coolingTout_Set_min_BLRU = data.getDouble("coolingTout_Set_min_BLRU");
        double coolingTout_Set_max_BLRU = data.getDouble("coolingTout_Set_max_BLRU");
        int N_User1Pump_CBLRS = data.getInt("N_User1Pump_CBLRS");
        double nominalFlow_User1Pump_CBLRS = data.getDouble("nominalFlow_User1Pump_CBLRS");
        double nominalHead_User1Pump_CBLRS = data.getDouble("nominalHead_User1Pump_CBLRS");
        double minFrequency_User1Pump_CBLRS = data.getDouble("minFrequency_User1Pump_CBLRS");
        double maxFrequency_User1Pump_CBLRS = data.getDouble("maxFrequency_User1Pump_CBLRS");
        double[] flowHead_User1Pump_Parameter_CBLRS = DataConverter.toDoubleArray(data.getString("flowHead_User1Pump_Parameter_CBLRS"));
        double[] flowEfficiency_User1Pump_Parameter_CBLRS = DataConverter.toDoubleArray(data.getString("flowEfficiency_User1Pump_Parameter_CBLRS"));
        double[] flow_User1Pump_CBLRS = DataConverter.toDoubleArray(data.getString("flow_User1Pump_CBLRS"));
        int N_SourcePump_CBLRS = data.getInt("N_SourcePump_CBLRS");
        double nominalFlow_SourcePump_CBLRS = data.getDouble("nominalFlow_SourcePump_CBLRS");
        double nominalHead_SourcePump_CBLRS = data.getDouble("nominalHead_SourcePump_CBLRS");
        double minFrequency_SourcePump_CBLRS = data.getDouble("minFrequency_SourcePump_CBLRS");
        double maxFrequency_SourcePump_CBLRS = data.getDouble("maxFrequency_SourcePump_CBLRS");
        double[] flowHead_SourcePump_Parameter_CBLRS = DataConverter.toDoubleArray(data.getString("flowHead_SourcePump_Parameter_CBLRS"));
        double[] flowEfficiency_SourcePump_Parameter_CBLRS = DataConverter.toDoubleArray(data.getString("flowEfficiency_SourcePump_Parameter_CBLRS"));
        double[] flow_SourcePump_CBLRS = DataConverter.toDoubleArray(data.getString("flow_SourcePump_CBLRS"));
        CBLRS cblrs = new CBLRS(N_BLRU, BLRU_Form, nominalCoolingLoad_BLRU, nominalCoolingElectricPower_BLRU, nominalCoolingTin_load_BLRU, nominalCoolingTout_load_BLRU, nominalCoolingTin_source_BLRU, nominalCoolingTout_source_BLRU, cooling_Parameter_BLRU1, cooling_Parameter_BLRU2, cooling_Parameter_BLRU3, cooling_Parameter_BLRU4, coolingTout_Set_min_BLRU, coolingTout_Set_max_BLRU, N_User1Pump_CBLRS, nominalFlow_User1Pump_CBLRS, nominalHead_User1Pump_CBLRS, minFrequency_User1Pump_CBLRS, maxFrequency_User1Pump_CBLRS, flowHead_User1Pump_Parameter_CBLRS, flowEfficiency_User1Pump_Parameter_CBLRS, flow_User1Pump_CBLRS, N_SourcePump_CBLRS, nominalFlow_SourcePump_CBLRS, nominalHead_SourcePump_CBLRS, minFrequency_SourcePump_CBLRS, maxFrequency_SourcePump_CBLRS, flowHead_SourcePump_Parameter_CBLRS, flowEfficiency_SourcePump_Parameter_CBLRS, flow_SourcePump_CBLRS);
        int N_OpenTower = data.getInt("N_OpenTower");
        double nominalLoad_OpenTower = data.getDouble("nominalLoad_OpenTower");
        double nominalFlow_OpenTower = data.getDouble("nominalFlow_OpenTower");
        double nominal_a_OpenTower = data.getDouble("nominal_a_OpenTower");
        double nominal_Ts_OpenTower = data.getDouble("nominal_Ts_OpenTower");
        double nominalPower_OpenTower = data.getDouble("nominalPower_OpenTower");
        double minFrequency_OpenTower = data.getDouble("minFrequency_OpenTower");
        double maxFrequency_OpenTower = data.getDouble("maxFrequency_OpenTower");
        double[] power_OpenTower_Parameter = DataConverter.toDoubleArray(data.getString("power_OpenTower_Parameter"));
        OpenTower openTower = new OpenTower(N_OpenTower, nominalLoad_OpenTower, nominalFlow_OpenTower, nominal_a_OpenTower, nominal_Ts_OpenTower, nominalPower_OpenTower, minFrequency_OpenTower, maxFrequency_OpenTower, power_OpenTower_Parameter);
        String operationModel = data.getString("operationModel");
        int dayPlanStartTime = data.getInt("dayPlanStartTime");
        int controlInterval = data.getInt("controlInterval");
        double tout_cooling_min = data.getDouble("tout_cooling_min");
        double tout_cooling_max = data.getDouble("tout_cooling_max");
        double deltaT_cooling_expectation = data.getDouble("deltaT_cooling_expectation");
        double iceMakingTout_load_DOCU = data.getDouble("iceMakingTout_load_DOCU");
        double expectDeltaT_OT = data.getDouble("expectDeltaT_OT");
        double expectDeltaT_IST_charge = data.getDouble("expectDeltaT_IST_charge");
        double expectDeltaT_IST_discharge = data.getDouble("expectDeltaT_IST_discharge");
        String economicParameterModel = data.getString("economicParameterModel");
        double economicSingleElectricityPrice = data.getDouble("economicSingleElectricityPrice");
        double[] economicTimeSharingElectricityPrice = DataConverter.toDoubleArray(data.getString("economicTimeSharingElectricityPrice"));
        int priceElecUnit = data.getInt("priceElecUnit");
        double economicWaterPrice = data.getDouble("economicWaterPrice");
        String carbonParameterModel = data.getString("carbonParameterModel");
        double carbonParameterFixedCarbonFactor = data.getDouble("carbonParameterFixedCarbonFactor");
        double[] carbonParameterDynamicCarbonFactor = DataConverter.toDoubleArray(data.getString("carbonParameterDynamicCarbonFactor"));
        ArrayList<Double> STCLF = DataConverter.toDoubleList(data.getString("STCLF"));
        double to = data.getDouble("to");
        double rH = data.getDouble("rH");

        ArrayList<String> operationConditionCBLRS = DataConverter.toStringList(data, "operationConditionCBLRS");
        ArrayList<Integer> n_RunArrayBLRU = DataConverter.toIntegerList(data, "n_RunArrayBLRU");
        ArrayList<Double> coolingLoadHourArrayCBLRS = DataConverter.toDoubleList(data, "coolingLoadHourArrayCBLRS");
        ArrayList<String> operationConditionISS = DataConverter.toStringList(data, "operationConditionISS");
        ArrayList<Integer> n_RunArrayDOCU = DataConverter.toIntegerList(data, "n_RunArrayDOCU");
        ArrayList<Double> loadHourArrayISS = DataConverter.toDoubleList(data, "loadHourArrayISS");
        ArrayList<Double> coolingLoadHourArrayISS = DataConverter.toDoubleList(data, "coolingLoadHourArrayISS");
        ArrayList<Double> iceMakingLoadHourArrayISS = DataConverter.toDoubleList(data, "iceMakingLoadHourArrayISS");
        ArrayList<Double> iceMeltingLoadHourArrayISS = DataConverter.toDoubleList(data, "iceMeltingLoadHourArrayISS");
        ArrayList<Integer> n_RunArrayOT = DataConverter.toIntegerList(data, "n_RunArrayOT");
        ArrayList<Integer> n_RunArrayDOCU_history = DataConverter.toIntegerList(data.getString("n_RunArrayDOCU_history"));
        ArrayList<Double> tin_IST_history = DataConverter.toDoubleList(data.getString("tin_IST_history"));
        ArrayList<Double> tout_IST_history = DataConverter.toDoubleList(data.getString("tout_IST_history"));
        ArrayList<Double> flow_ISThistory = DataConverter.toDoubleList(data.getString("flow_ISThistory"));
        ArrayList<Double> storageCapacity_IST_history = DataConverter.toDoubleList(data.getString("storageCapacity_IST_history"));
        ArrayList<Integer> breakdownDOCU = DataConverter.toIntegerList(data.getString("breakdownDOCU"));
        ArrayList<Integer> breakdownSourcePumpISS = DataConverter.toIntegerList(data.getString("breakdownSourcePumpISS"));
        ArrayList<Integer> breakdownUser1PumpISS = DataConverter.toIntegerList(data.getString("breakdownUser1PumpISS"));
        ArrayList<Integer> breakdownEthylAlcoholPumpISS = DataConverter.toIntegerList(data.getString("breakdownEthylAlcoholPumpISS"));
        ArrayList<Integer> breakdownBLRU = DataConverter.toIntegerList(data.getString("breakdownBLRU"));
        ArrayList<Integer> breakdownSourcePumpCBLRS = DataConverter.toIntegerList(data.getString("breakdownSourcePumpCBLRS"));
        ArrayList<Integer> breakdownUser1PumpCBLRS = DataConverter.toIntegerList(data.getString("breakdownUser1PumpCBLRS"));
        ArrayList<Integer> breakdownOT = DataConverter.toIntegerList(data.getString("breakdownOT"));
        ArrayList<Integer> currentStateDOCU = DataConverter.toIntegerList(data.getString("currentStateDOCU"));
        ArrayList<Integer> currentStateSourcePumpISS = DataConverter.toIntegerList(data.getString("currentStateSourcePumpISS"));
        ArrayList<Integer> currentStateUser1PumpISS = DataConverter.toIntegerList(data.getString("currentStateUser1PumpISS"));
        ArrayList<Integer> currentStateEthylAlcoholPumpISS = DataConverter.toIntegerList(data.getString("currentStateEthylAlcoholPumpISS"));
        ArrayList<Integer> currentStateBLRU = DataConverter.toIntegerList(data.getString("currentStateBLRU"));
        ArrayList<Integer> currentStateSourcePumpCBLRS = DataConverter.toIntegerList(data.getString("currentStateSourcePumpCBLRS"));
        ArrayList<Integer> currentStateUser1PumpCBLRS = DataConverter.toIntegerList(data.getString("currentStateUser1PumpCBLRS"));
        ArrayList<Integer> currentStateOT = DataConverter.toIntegerList(data.getString("currentStateOT"));
        ArrayList<Double> runTimeDOCU = DataConverter.toDoubleList(data.getString("runTimeDOCU"));
        ArrayList<Double> runTimeSourcePumpISS = DataConverter.toDoubleList(data.getString("runTimeSourcePumpISS"));
        ArrayList<Double> runTimeUser1PumpISS = DataConverter.toDoubleList(data.getString("runTimeUser1PumpISS"));
        ArrayList<Double> runTimeEthylAlcoholPumpISS = DataConverter.toDoubleList(data.getString("runTimeEthylAlcoholPumpISS"));
        ArrayList<Double> runTimeBLRU = DataConverter.toDoubleList(data.getString("runTimeBLRU"));
        ArrayList<Double> runTimeSourcePumpCBLRS = DataConverter.toDoubleList(data.getString("runTimeSourcePumpCBLRS"));
        ArrayList<Double> runTimeUser1PumpCBLRS = DataConverter.toDoubleList(data.getString("runTimeUser1PumpCBLRS"));
        ArrayList<Double> runTimeOT = DataConverter.toDoubleList(data.getString("runTimeOT"));
        double load_Cooling_Design = data.getDouble("load_Cooling_Design");
        double Tn_Cooling_Design = data.getDouble("Tn_Cooling_Design");
        double n_rH_Cooling_Design = data.getDouble("n_rH_Cooling_Design");
        double To_Cooling_Design = data.getDouble("To_Cooling_Design");
        double o_rH_Cooling_Design = data.getDouble("o_rH_Cooling_Design");
        double Twb_cooling_Design = data.getDouble("Twb_cooling_Design");
        double Tout_User_Cooling_Design = data.getDouble("Tout_User_Cooling_Design");
        double Tin_User_Cooling_Design = data.getDouble("Tin_User_Cooling_Design");
        double flow_Cooling_Design = data.getDouble("flow_Cooling_Design");
        User user = new User(load_Cooling_Design, Tn_Cooling_Design, n_rH_Cooling_Design, To_Cooling_Design, o_rH_Cooling_Design, Twb_cooling_Design, Tout_User_Cooling_Design, Tin_User_Cooling_Design, flow_Cooling_Design);
        System.out.println("***********************************************");
        ResponseOptHour responseOptHour = (new OptimalHour()).optimalHour(operationModel, dayPlanStartTime, controlInterval, tout_cooling_min, tout_cooling_max, deltaT_cooling_expectation, iceMakingTout_load_DOCU, expectDeltaT_OT, expectDeltaT_IST_charge, expectDeltaT_IST_discharge, economicParameterModel, economicTimeSharingElectricityPrice, priceElecUnit, economicWaterPrice, carbonParameterDynamicCarbonFactor, STCLF, to, rH, operationConditionCBLRS, n_RunArrayBLRU, coolingLoadHourArrayCBLRS, operationConditionISS, n_RunArrayDOCU, loadHourArrayISS, coolingLoadHourArrayISS, iceMakingLoadHourArrayISS, iceMeltingLoadHourArrayISS, n_RunArrayOT, n_RunArrayDOCU_history, tin_IST_history, tout_IST_history, flow_ISThistory, storageCapacity_IST_history, breakdownDOCU, breakdownSourcePumpISS, breakdownUser1PumpISS, breakdownEthylAlcoholPumpISS, breakdownBLRU, breakdownSourcePumpCBLRS, breakdownUser1PumpCBLRS, breakdownOT, currentStateDOCU, currentStateSourcePumpISS, currentStateUser1PumpISS, currentStateEthylAlcoholPumpISS, currentStateBLRU, currentStateSourcePumpCBLRS, currentStateUser1PumpCBLRS, currentStateOT, runTimeDOCU, runTimeSourcePumpISS, runTimeUser1PumpISS, runTimeEthylAlcoholPumpISS, runTimeBLRU, runTimeSourcePumpCBLRS, runTimeUser1PumpCBLRS, runTimeOT, cblrs, iss, openTower, user);

        System.out.println("日内优化完成");

        String resultFile = "hour.csv";
        responseOptHour.saveToCSV(resultFile);

        return read(resultFile);
    }

    private static JSONObject read(String filename) {
        try (BufferedReader reader = Files.newBufferedReader(Paths.get(filename), StandardCharsets.UTF_8)) {
            String line = reader.readLine();
            String[] names = line.split(",");
            List<String> nameList = new ArrayList<>(names.length);
            for (String name : names) {
                nameList.add(name.trim());
            }
            List<List<String>> rowList = new ArrayList<>();
            while ((line = reader.readLine()) != null) {
                String[] values = line.split(",");
                List<String> valueList = new ArrayList<>(values.length);
                for (String value : values) {
                    valueList.add(value.trim());
                }
                rowList.add(valueList);
            }
            List<Map<String, String>> resultList = new ArrayList<>();
            for (List<String> valueList : rowList) {
                Map<String, String> map = new HashMap<>();
                for (int i = 0; i < nameList.size(); i++) {
                    map.put(nameList.get(i), valueList.get(i));
                }
                resultList.add(map);
            }
            return new JSONObject(resultList.get(0));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
